﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 低频天线阵列相控阵信号发生系统SmartFASK12.Controls
{
    public class MConvert
    {
        private static MConvert _instance = null;
        private MConvert()
        {

        }

        public static MConvert Singleton()
        {
            if (_instance == null)
            {
                _instance = new MConvert();
            }

            return _instance;
        }



        /// <summary>
        /// K转Int
        /// </summary>
        /// <param name="k"></param>
        /// <returns></returns>
        public int KToInt(string k)
        {
            string kStr = k.Replace('K', 'k');
            int value;
            if (kStr.Contains("k"))
            {
                value = Convert.ToInt32(Convert.ToDouble(kStr.Replace('k', ' ')) * 1000);
            }
            else
            {
                value = (int)Convert.ToDouble(kStr);
            }
            return value;
        }

        /// <summary>
        /// K转Double
        /// </summary>
        /// <param name="k"></param>
        /// <returns></returns>
        public double KToDouble(string k)
        {
            string kStr = k.Replace('K', 'k');
            double value;
            if (kStr.Contains("k"))
            {
                value = Convert.ToDouble(Convert.ToDouble(kStr.Replace('k', ' ')) * 1000);
            }
            else
            {
                value = Convert.ToDouble(kStr);
            }
            return value;
        }
    }
}
